{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "# This notebook shows example to load the CHGNet for prediction\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    from chgnet.model import CHGNet\n",
    "except ImportError:\n",
    "    # install CHGNet (only needed on Google Colab or if you didn't install CHGNet yet)\n",
    "    !pip install chgnet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from pymatgen.core import Structure\n",
    "\n",
    "from chgnet.model import CHGNet\n",
    "\n",
    "# If the above line fails in Google Colab due to numpy version issue,\n",
    "# please restart the runtime, and the problem will be solved\n",
    "\n",
    "np.set_printoptions(precision=4, suppress=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3",
   "metadata": {},
   "source": [
    "### Read structure from a json or cif file\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Formula (Li2 Mn2 O4)\n",
      "Reduced Formula: LiMnO2\n",
      "abc   :   2.868779   4.634475   5.832507\n",
      "angles:  90.000000  90.000000  90.000000\n",
      "pbc   :       True       True       True\n",
      "Sites (8)\n",
      "  #  SP      a    b         c\n",
      "---  ----  ---  ---  --------\n",
      "  0  Li+   0.5  0.5  0.37975\n",
      "  1  Li+   0    0    0.62025\n",
      "  2  Mn3+  0.5  0.5  0.863252\n",
      "  3  Mn3+  0    0    0.136747\n",
      "  4  O2-   0.5  0    0.360824\n",
      "  5  O2-   0    0.5  0.098514\n",
      "  6  O2-   0.5  0    0.901486\n",
      "  7  O2-   0    0.5  0.639176\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    from chgnet import ROOT\n",
    "\n",
    "    structure = Structure.from_file(f\"{ROOT}/examples/mp-18767-LiMnO2.cif\")\n",
    "except Exception:\n",
    "    from urllib.request import urlopen\n",
    "\n",
    "    url = \"https://raw.githubusercontent.com/CederGroupHub/chgnet/main/examples/mp-18767-LiMnO2.cif\"\n",
    "    cif = urlopen(url).read().decode(\"utf-8\")\n",
    "    structure = Structure.from_str(cif, fmt=\"cif\")\n",
    "\n",
    "print(structure)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5",
   "metadata": {},
   "source": [
    "### Define Model\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CHGNet v0.3.0 initialized with 412,525 parameters\n",
      "CHGNet will run on cpu\n"
     ]
    }
   ],
   "source": [
    "chgnet = CHGNet.load()\n",
    "\n",
    "# Alternatively you can read your own model\n",
    "# chgnet = CHGNet.from_file(model_path)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7",
   "metadata": {},
   "source": [
    "# Predict energy, force, stress, magmom\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CHGNet-predicted energy (eV/atom):\n",
      "-7.367691516876221\n",
      "\n",
      "CHGNet-predicted forces (eV/A):\n",
      "[[ 0.     -0.      0.0238]\n",
      " [ 0.      0.     -0.0238]\n",
      " [ 0.     -0.      0.0926]\n",
      " [-0.     -0.     -0.0926]\n",
      " [ 0.      0.     -0.0024]\n",
      " [-0.     -0.     -0.0131]\n",
      " [ 0.      0.      0.0131]\n",
      " [-0.      0.      0.0024]]\n",
      "\n",
      "CHGNet-predicted stress (GPa):\n",
      "[[-0.3037 -0.      0.    ]\n",
      " [-0.      0.2231 -0.    ]\n",
      " [ 0.     -0.     -0.1074]]\n",
      "\n",
      "CHGNet-predicted magmom (mu_B):\n",
      "[0.003  0.003  3.8694 3.8694 0.0441 0.0386 0.0386 0.0441]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "prediction = chgnet.predict_structure(structure)\n",
    "\n",
    "for key, unit in [\n",
    "    (\"energy\", \"eV/atom\"),\n",
    "    (\"forces\", \"eV/A\"),\n",
    "    (\"stress\", \"GPa\"),\n",
    "    (\"magmom\", \"mu_B\"),\n",
    "]:\n",
    "    print(f\"CHGNet-predicted {key} ({unit}):\\n{prediction[key[0]]}\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9",
   "metadata": {},
   "source": [
    "# Structure Optimization\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CHGNet v0.3.0 initialized with 412,525 parameters\n",
      "CHGNet will run on cpu\n"
     ]
    }
   ],
   "source": [
    "from chgnet.model import StructOptimizer\n",
    "\n",
    "relaxer = StructOptimizer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      Step     Time          Energy          fmax\n",
      "FIRE:    0 14:37:08      -58.683239        2.601857\n",
      "FIRE:    1 14:37:08      -58.812550        1.642414\n",
      "FIRE:    2 14:37:08      -58.905983        0.343259\n",
      "FIRE:    3 14:37:08      -58.881161        1.028341\n",
      "FIRE:    4 14:37:09      -58.887203        0.944485\n",
      "FIRE:    5 14:37:09      -58.897339        0.789977\n",
      "FIRE:    6 14:37:09      -58.908859        0.598800\n",
      "FIRE:    7 14:37:09      -58.918888        0.364584\n",
      "FIRE:    8 14:37:09      -58.924923        0.167921\n",
      "FIRE:    9 14:37:10      -58.926193        0.189265\n",
      "FIRE:   10 14:37:10      -58.926289        0.186574\n",
      "FIRE:   11 14:37:10      -58.926487        0.181227\n",
      "FIRE:   12 14:37:10      -58.926773        0.176636\n",
      "FIRE:   13 14:37:10      -58.927135        0.171366\n",
      "FIRE:   14 14:37:10      -58.927570        0.165129\n",
      "FIRE:   15 14:37:11      -58.928059        0.158151\n",
      "FIRE:   16 14:37:11      -58.928581        0.150665\n",
      "FIRE:   17 14:37:11      -58.929195        0.142299\n",
      "FIRE:   18 14:37:11      -58.929893        0.133674\n",
      "FIRE:   19 14:37:12      -58.930668        0.125058\n",
      "FIRE:   20 14:37:12      -58.931519        0.122115\n",
      "FIRE:   21 14:37:12      -58.932449        0.117856\n",
      "FIRE:   22 14:37:12      -58.933479        0.112667\n",
      "FIRE:   23 14:37:12      -58.934654        0.109456\n",
      "FIRE:   24 14:37:12      -58.935978        0.102994\n",
      "FIRE:   25 14:37:13      -58.937443        0.086996\n",
      "Relaxed structure:\n",
      "\n",
      "Full Formula (Li2 Mn2 O4)\n",
      "Reduced Formula: LiMnO2\n",
      "abc   :   2.873358   4.632859   5.838570\n",
      "angles:  89.977879  89.981979  90.001029\n",
      "pbc   :       True       True       True\n",
      "Sites (8)\n",
      "  #  SP           a         b         c      magmom\n",
      "---  ----  --------  --------  --------  ----------\n",
      "  0  Li+   0.525688  0.503384  0.378774  0.00299916\n",
      "  1  Li+   0.013925  0.005015  0.611163  0.00258121\n",
      "  2  Mn3+  0.507764  0.514685  0.866373  3.87553\n",
      "  3  Mn3+  1.00202   0.01337   0.130907  3.86949\n",
      "  4  O2-   0.502668  0.011507  0.356006  0.0451363\n",
      "  5  O2-   0.006044  0.514345  0.101121  0.0383126\n",
      "  6  O2-   0.500941  0.016711  0.89802   0.0374973\n",
      "  7  O2-   0.009288  0.516042  0.642107  0.046883\n"
     ]
    }
   ],
   "source": [
    "# Perturb the structure\n",
    "structure.perturb(0.1)\n",
    "\n",
    "# Relax the perturbed structure\n",
    "result = relaxer.relax(structure, verbose=True)\n",
    "print(\"Relaxed structure:\\n\")\n",
    "print(result[\"final_structure\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12",
   "metadata": {},
   "source": [
    "# Molecular Dynamics\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CHGNet will run on cpu\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/janosh/.venv/py310/lib/python3.10/site-packages/ase/md/nvtberendsen.py:95: RuntimeWarning: divide by zero encountered in scalar divide\n",
      "  (self.temperature / old_temperature - 1.0) *\n"
     ]
    }
   ],
   "source": [
    "from chgnet.model.dynamics import MolecularDynamics\n",
    "\n",
    "md = MolecularDynamics(\n",
    "    atoms=structure,\n",
    "    model=chgnet,\n",
    "    ensemble=\"nvt\",\n",
    "    temperature=1000,  # in k\n",
    "    timestep=2,  # in fs\n",
    "    trajectory=\"md_out.traj\",\n",
    "    logfile=\"md_out.log\",\n",
    "    loginterval=100,\n",
    ")\n",
    "md.run(50)  # run a 0.1 ps MD simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14",
   "metadata": {},
   "source": [
    "# Magmom Visualization\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Li+16 Mn3+16 O2-32\n"
     ]
    }
   ],
   "source": [
    "supercell = structure.make_supercell([2, 2, 2], in_place=False)\n",
    "print(supercell.composition)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Li+8 Mn3+16 O2-32\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "n_Li = int(supercell.composition[\"Li+\"])\n",
    "remove_ids = random.sample(list(range(n_Li)), n_Li // 2)\n",
    "\n",
    "supercell.remove_sites(remove_ids)\n",
    "print(supercell.composition)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      Step     Time          Energy         fmax\n",
      "*Force-consistent energies used in optimization.\n",
      "FIRE:    0 19:33:07     -426.191837*      20.8815\n",
      "FIRE:    1 19:33:07     -400.066006*     268.6776\n",
      "FIRE:    2 19:33:07     -426.080700*      50.7814\n",
      "FIRE:    3 19:33:08     -427.411331*       4.2803\n",
      "FIRE:    4 19:33:08     -426.366394*      52.4735\n",
      "FIRE:    5 19:33:08     -426.988091*      35.4947\n",
      "FIRE:    6 19:33:09     -427.518917*       9.0208\n",
      "FIRE:    7 19:33:09     -427.456432*      15.6711\n",
      "FIRE:    8 19:33:09     -427.474777*      14.7084\n",
      "FIRE:    9 19:33:09     -427.507435*      12.8331\n",
      "FIRE:   10 19:33:10     -427.547436*      10.1189\n",
      "FIRE:   11 19:33:10     -427.586182*       6.6958\n",
      "FIRE:   12 19:33:11     -427.616276*       2.8986\n",
      "FIRE:   13 19:33:11     -427.633926*       1.8915\n",
      "FIRE:   14 19:33:12     -427.641483*       4.3156\n",
      "FIRE:   15 19:33:12     -427.646664*       7.0416\n",
      "FIRE:   16 19:33:13     -427.658947*       8.6467\n",
      "FIRE:   17 19:33:14     -427.687492*       8.7184\n",
      "FIRE:   18 19:33:15     -427.735184*       6.9920\n",
      "FIRE:   19 19:33:15     -427.794090*       3.5248\n",
      "FIRE:   20 19:33:16     -427.848511*       1.6643\n",
      "FIRE:   21 19:33:16     -427.894413*       4.9746\n",
      "FIRE:   22 19:33:16     -427.952999*       6.5308\n",
      "FIRE:   23 19:33:17     -428.042641*       4.6589\n",
      "FIRE:   24 19:33:17     -428.143631*       1.3525\n",
      "FIRE:   25 19:33:17     -428.232498*       5.1136\n",
      "FIRE:   26 19:33:18     -428.347214*       4.8204\n",
      "FIRE:   27 19:33:18     -428.480595*       1.1006\n",
      "FIRE:   28 19:33:18     -428.598328*       4.7845\n",
      "FIRE:   29 19:33:19     -428.742523*       0.7454\n",
      "FIRE:   30 19:33:19     -428.856838*       5.3981\n",
      "FIRE:   31 19:33:19     -428.986641*       1.8158\n",
      "FIRE:   32 19:33:20     -429.089661*       1.6937\n",
      "FIRE:   33 19:33:20     -429.157326*       6.4389\n",
      "FIRE:   34 19:33:20     -429.204376*       9.4077\n",
      "FIRE:   35 19:33:21     -429.258823*       2.9069\n",
      "FIRE:   36 19:33:21     -429.253883*       5.7814\n",
      "FIRE:   37 19:33:21     -429.261921*       4.6831\n",
      "FIRE:   38 19:33:22     -429.273216*       2.7183\n",
      "FIRE:   39 19:33:22     -429.281761*       0.8040\n",
      "FIRE:   40 19:33:22     -429.285206*       1.9802\n",
      "FIRE:   41 19:33:22     -429.286995*       3.4904\n",
      "FIRE:   42 19:33:23     -429.292202*       4.0133\n",
      "FIRE:   43 19:33:23     -429.302509*       3.5601\n",
      "FIRE:   44 19:33:24     -429.317356*       2.0857\n",
      "FIRE:   45 19:33:24     -429.331936*       0.7369\n",
      "FIRE:   46 19:33:24     -429.343819*       2.3423\n",
      "FIRE:   47 19:33:25     -429.359760*       3.0563\n",
      "FIRE:   48 19:33:25     -429.384968*       1.6785\n",
      "FIRE:   49 19:33:26     -429.411137*       1.2078\n",
      "FIRE:   50 19:33:26     -429.437439*       2.7280\n",
      "FIRE:   51 19:33:27     -429.475330*       1.0137\n",
      "FIRE:   52 19:33:27     -429.512047*       2.4103\n",
      "FIRE:   53 19:33:27     -429.558777*       1.4587\n",
      "FIRE:   54 19:33:28     -429.605507*       2.8929\n",
      "FIRE:   55 19:33:28     -429.666443*       0.6083\n",
      "FIRE:   56 19:33:29     -429.725990*       3.0751\n",
      "FIRE:   57 19:33:29     -429.791145*       4.6636\n",
      "FIRE:   58 19:33:29     -429.865753*       5.8153\n",
      "FIRE:   59 19:33:30     -429.921108*       9.5566\n",
      "FIRE:   60 19:33:30     -429.977825*       0.8973\n",
      "FIRE:   61 19:33:31     -429.945328*       8.6144\n",
      "FIRE:   62 19:33:31     -429.963219*       6.5255\n",
      "FIRE:   63 19:33:31     -429.983513*       2.9099\n",
      "FIRE:   64 19:33:31     -429.989948*       1.2587\n",
      "FIRE:   65 19:33:32     -429.990215*       1.1859\n",
      "FIRE:   66 19:33:32     -429.990803*       1.0439\n",
      "FIRE:   67 19:33:32     -429.991604*       0.8427\n",
      "FIRE:   68 19:33:33     -429.992565*       0.5961\n",
      "FIRE:   69 19:33:33     -429.993660*       0.5577\n",
      "FIRE:   70 19:33:33     -429.994915*       0.5565\n",
      "FIRE:   71 19:33:34     -429.996277*       0.5552\n",
      "FIRE:   72 19:33:34     -429.997959*       0.5539\n",
      "FIRE:   73 19:33:35     -430.000069*       0.6014\n",
      "FIRE:   74 19:33:35     -430.002766*       0.6651\n",
      "FIRE:   75 19:33:35     -430.006184*       0.5923\n",
      "FIRE:   76 19:33:36     -430.010456*       0.5480\n",
      "FIRE:   77 19:33:36     -430.015663*       0.5464\n",
      "FIRE:   78 19:33:36     -430.021885*       0.5441\n",
      "FIRE:   79 19:33:37     -430.029495*       0.5407\n",
      "FIRE:   80 19:33:37     -430.038841*       0.5353\n",
      "FIRE:   81 19:33:37     -430.050217*       0.5278\n",
      "FIRE:   82 19:33:38     -430.063702*       0.5186\n",
      "FIRE:   83 19:33:38     -430.079990*       0.5087\n",
      "FIRE:   84 19:33:38     -430.099483*       0.4983\n",
      "FIRE:   85 19:33:38     -430.122448*       0.4984\n",
      "FIRE:   86 19:33:39     -430.149818*       0.5053\n",
      "FIRE:   87 19:33:39     -430.181835*       0.5115\n",
      "FIRE:   88 19:33:39     -430.219460*       0.5180\n",
      "FIRE:   89 19:33:40     -430.263306*       0.5171\n",
      "FIRE:   90 19:33:40     -430.314095*       0.5071\n",
      "FIRE:   91 19:33:40     -430.371933*       1.0597\n",
      "FIRE:   92 19:33:40     -430.432468*       3.0068\n",
      "FIRE:   93 19:33:41     -430.469879*       7.7926\n",
      "FIRE:   94 19:33:41     -430.507557*       0.7609\n",
      "FIRE:   95 19:33:41     -430.483631*       7.0410\n",
      "FIRE:   96 19:33:41     -430.495754*       5.3189\n",
      "FIRE:   97 19:33:42     -430.509346*       2.3629\n",
      "FIRE:   98 19:33:42     -430.513191*       1.0736\n",
      "FIRE:   99 19:33:42     -430.513378*       1.0133\n",
      "FIRE:  100 19:33:43     -430.513672*       0.8952\n",
      "FIRE:  101 19:33:43     -430.514099*       0.7276\n",
      "FIRE:  102 19:33:43     -430.514606*       0.5221\n",
      "FIRE:  103 19:33:43     -430.515167*       0.4073\n",
      "FIRE:  104 19:33:44     -430.515781*       0.4066\n",
      "FIRE:  105 19:33:44     -430.516396*       0.4058\n",
      "FIRE:  106 19:33:44     -430.517197*       0.4050\n",
      "FIRE:  107 19:33:45     -430.518185*       0.4784\n",
      "FIRE:  108 19:33:45     -430.519440*       0.5301\n",
      "FIRE:  109 19:33:45     -430.521095*       0.4690\n",
      "FIRE:  110 19:33:45     -430.523151*       0.4019\n",
      "FIRE:  111 19:33:46     -430.525608*       0.4010\n",
      "FIRE:  112 19:33:46     -430.528572*       0.3998\n",
      "FIRE:  113 19:33:46     -430.532204*       0.4188\n",
      "FIRE:  114 19:33:47     -430.536690*       0.3951\n",
      "FIRE:  115 19:33:47     -430.542137*       0.3911\n",
      "FIRE:  116 19:33:47     -430.548653*       0.3864\n",
      "FIRE:  117 19:33:47     -430.556530*       0.3839\n",
      "FIRE:  118 19:33:48     -430.566036*       0.3823\n",
      "FIRE:  119 19:33:48     -430.577251*       0.3796\n",
      "FIRE:  120 19:33:48     -430.590683*       0.3734\n",
      "FIRE:  121 19:33:49     -430.606411*       0.3682\n",
      "FIRE:  122 19:33:49     -430.624916*       0.3595\n",
      "FIRE:  123 19:33:49     -430.646439*       0.3481\n",
      "FIRE:  124 19:33:49     -430.671165*       0.3711\n",
      "FIRE:  125 19:33:49     -430.698856*       0.9553\n",
      "FIRE:  126 19:33:50     -430.726494*       2.5699\n",
      "FIRE:  127 19:33:50     -430.739819*       6.1438\n",
      "FIRE:  128 19:33:50     -430.763103*       0.5290\n",
      "FIRE:  129 19:33:51     -430.747082*       5.6183\n",
      "FIRE:  130 19:33:51     -430.754772*       4.2524\n",
      "FIRE:  131 19:33:51     -430.763371*       1.8824\n",
      "FIRE:  132 19:33:52     -430.765507*       0.8726\n",
      "FIRE:  133 19:33:52     -430.765614*       0.8221\n",
      "FIRE:  134 19:33:52     -430.765774*       0.7238\n",
      "FIRE:  135 19:33:52     -430.765987*       0.5846\n",
      "FIRE:  136 19:33:53     -430.766228*       0.4136\n",
      "FIRE:  137 19:33:53     -430.766521*       0.2609\n",
      "FIRE:  138 19:33:53     -430.766788*       0.2602\n",
      "FIRE:  139 19:33:53     -430.767056*       0.2595\n",
      "FIRE:  140 19:33:54     -430.767429*       0.3020\n",
      "FIRE:  141 19:33:54     -430.767830*       0.4131\n",
      "FIRE:  142 19:33:54     -430.768391*       0.4527\n",
      "FIRE:  143 19:33:54     -430.769112*       0.3991\n",
      "FIRE:  144 19:33:55     -430.770046*       0.2572\n",
      "FIRE:  145 19:33:55     -430.771141*       0.2570\n",
      "FIRE:  146 19:33:55     -430.772449*       0.2567\n",
      "FIRE:  147 19:33:55     -430.774025*       0.3410\n",
      "FIRE:  148 19:33:56     -430.776001*       0.2755\n",
      "FIRE:  149 19:33:56     -430.778431*       0.2515\n",
      "FIRE:  150 19:33:56     -430.781315*       0.2577\n",
      "FIRE:  151 19:33:56     -430.784840*       0.2741\n",
      "FIRE:  152 19:33:57     -430.789112*       0.2429\n",
      "FIRE:  153 19:33:57     -430.794159*       0.2999\n",
      "FIRE:  154 19:33:57     -430.800327*       0.2338\n",
      "FIRE:  155 19:33:57     -430.807564*       0.3074\n",
      "FIRE:  156 19:33:58     -430.816242*       0.2299\n",
      "FIRE:  157 19:33:58     -430.826416*       0.2275\n",
      "FIRE:  158 19:33:58     -430.838299*       0.3640\n",
      "FIRE:  159 19:33:58     -430.851784*       0.8401\n",
      "FIRE:  160 19:33:58     -430.865456*       1.9682\n",
      "FIRE:  161 19:33:59     -430.872158*       4.5255\n",
      "FIRE:  162 19:33:59     -430.884949*       0.2940\n",
      "FIRE:  163 19:33:59     -430.875977*       4.1430\n",
      "FIRE:  164 19:33:59     -430.880329*       3.1247\n",
      "FIRE:  165 19:34:00     -430.885136*       1.3573\n",
      "FIRE:  166 19:34:00     -430.886257*       0.7005\n",
      "FIRE:  167 19:34:00     -430.886311*       0.6596\n",
      "FIRE:  168 19:34:00     -430.886391*       0.5795\n",
      "FIRE:  169 19:34:01     -430.886551*       0.4660\n",
      "FIRE:  170 19:34:01     -430.886684*       0.3273\n",
      "FIRE:  171 19:34:01     -430.886871*       0.2133\n",
      "FIRE:  172 19:34:01     -430.887032*       0.2133\n",
      "FIRE:  173 19:34:02     -430.887192*       0.2132\n",
      "FIRE:  174 19:34:02     -430.887379*       0.2477\n",
      "FIRE:  175 19:34:02     -430.887619*       0.3332\n",
      "FIRE:  176 19:34:02     -430.887939*       0.3596\n",
      "FIRE:  177 19:34:03     -430.888367*       0.3107\n",
      "FIRE:  178 19:34:03     -430.888901*       0.2128\n",
      "FIRE:  179 19:34:03     -430.889568*       0.2127\n",
      "FIRE:  180 19:34:03     -430.890289*       0.2126\n",
      "FIRE:  181 19:34:04     -430.891224*       0.2817\n",
      "FIRE:  182 19:34:04     -430.892399*       0.2163\n",
      "FIRE:  183 19:34:04     -430.893814*       0.2118\n",
      "FIRE:  184 19:34:04     -430.895523*       0.2150\n",
      "FIRE:  185 19:34:05     -430.897606*       0.2109\n",
      "FIRE:  186 19:34:05     -430.900169*       0.2103\n",
      "FIRE:  187 19:34:05     -430.903187*       0.2419\n",
      "FIRE:  188 19:34:05     -430.906898*       0.2088\n",
      "FIRE:  189 19:34:06     -430.911304*       0.2412\n",
      "FIRE:  190 19:34:06     -430.916645*       0.2065\n",
      "FIRE:  191 19:34:06     -430.923000*       0.2050\n",
      "FIRE:  192 19:34:06     -430.930557*       0.2460\n",
      "FIRE:  193 19:34:07     -430.939289*       0.6143\n",
      "FIRE:  194 19:34:07     -430.948341*       1.5686\n",
      "FIRE:  195 19:34:07     -430.952267*       3.8417\n",
      "FIRE:  196 19:34:07     -430.961479*       0.1961\n",
      "FIRE:  197 19:34:08     -430.954884*       3.5511\n",
      "FIRE:  198 19:34:08     -430.958141*       2.6560\n",
      "FIRE:  199 19:34:08     -430.961666*       1.1055\n",
      "FIRE:  200 19:34:08     -430.962360*       0.6877\n",
      "FIRE:  201 19:34:09     -430.962414*       0.6458\n",
      "FIRE:  202 19:34:09     -430.962467*       0.5647\n",
      "FIRE:  203 19:34:09     -430.962601*       0.4494\n",
      "FIRE:  204 19:34:09     -430.962761*       0.3076\n",
      "FIRE:  205 19:34:10     -430.962868*       0.1957\n",
      "FIRE:  206 19:34:10     -430.963001*       0.1957\n",
      "FIRE:  207 19:34:10     -430.963081*       0.1956\n",
      "FIRE:  208 19:34:10     -430.963242*       0.2653\n",
      "FIRE:  209 19:34:11     -430.963402*       0.3437\n",
      "FIRE:  210 19:34:11     -430.963642*       0.3611\n",
      "FIRE:  211 19:34:11     -430.963963*       0.3028\n",
      "FIRE:  212 19:34:11     -430.964363*       0.1953\n",
      "FIRE:  213 19:34:12     -430.964817*       0.1952\n",
      "FIRE:  214 19:34:12     -430.965378*       0.2026\n",
      "FIRE:  215 19:34:12     -430.966019*       0.2812\n",
      "FIRE:  216 19:34:12     -430.966900*       0.1990\n",
      "FIRE:  217 19:34:13     -430.967941*       0.1945\n",
      "FIRE:  218 19:34:13     -430.969143*       0.2280\n",
      "FIRE:  219 19:34:13     -430.970665*       0.1956\n",
      "FIRE:  220 19:34:13     -430.972534*       0.1934\n",
      "FIRE:  221 19:34:14     -430.974751*       0.2342\n",
      "FIRE:  222 19:34:14     -430.977501*       0.1923\n",
      "FIRE:  223 19:34:14     -430.980732*       0.2239\n",
      "FIRE:  224 19:34:14     -430.984684*       0.1908\n",
      "FIRE:  225 19:34:14     -430.989437*       0.1897\n",
      "FIRE:  226 19:34:15     -430.995098*       0.1885\n",
      "FIRE:  227 19:34:15     -431.001774*       0.4567\n",
      "FIRE:  228 19:34:15     -431.008770*       1.3171\n",
      "FIRE:  229 19:34:16     -431.011227*       3.5117\n",
      "FIRE:  230 19:34:16     -431.018890*       0.1842\n",
      "FIRE:  231 19:34:16     -431.013336*       3.2480\n",
      "FIRE:  232 19:34:16     -431.016167*       2.4052\n",
      "FIRE:  233 19:34:17     -431.019104*       0.9489\n",
      "FIRE:  234 19:34:17     -431.019531*       0.7231\n",
      "FIRE:  235 19:34:17     -431.019585*       0.6775\n",
      "FIRE:  236 19:34:17     -431.019665*       0.5892\n",
      "FIRE:  237 19:34:18     -431.019772*       0.4639\n",
      "FIRE:  238 19:34:18     -431.019905*       0.3108\n",
      "FIRE:  239 19:34:18     -431.020012*       0.1841\n",
      "FIRE:  240 19:34:18     -431.020119*       0.1840\n",
      "FIRE:  241 19:34:19     -431.020226*       0.1839\n",
      "FIRE:  242 19:34:19     -431.020306*       0.2966\n",
      "FIRE:  243 19:34:19     -431.020439*       0.3723\n",
      "FIRE:  244 19:34:19     -431.020626*       0.3810\n",
      "FIRE:  245 19:34:20     -431.020893*       0.3090\n",
      "FIRE:  246 19:34:20     -431.021240*       0.1837\n",
      "FIRE:  247 19:34:20     -431.021614*       0.1837\n",
      "FIRE:  248 19:34:20     -431.022041*       0.2324\n",
      "FIRE:  249 19:34:21     -431.022575*       0.2995\n",
      "FIRE:  250 19:34:21     -431.023243*       0.1952\n",
      "FIRE:  251 19:34:21     -431.024097*       0.1832\n",
      "FIRE:  252 19:34:21     -431.025059*       0.2517\n",
      "FIRE:  253 19:34:22     -431.026260*       0.1898\n",
      "FIRE:  254 19:34:22     -431.027756*       0.1826\n",
      "FIRE:  255 19:34:22     -431.029518*       0.2387\n",
      "FIRE:  256 19:34:22     -431.031734*       0.1818\n",
      "FIRE:  257 19:34:23     -431.034325*       0.2134\n",
      "FIRE:  258 19:34:23     -431.037476*       0.2340\n",
      "FIRE:  259 19:34:23     -431.041294*       0.1800\n",
      "FIRE:  260 19:34:24     -431.045834*       0.1792\n",
      "FIRE:  261 19:34:24     -431.051308*       0.2511\n",
      "FIRE:  262 19:34:24     -431.057369*       0.8971\n",
      "FIRE:  263 19:34:24     -431.060360*       2.8511\n",
      "FIRE:  264 19:34:25     -431.065434*       0.1750\n",
      "FIRE:  265 19:34:25     -431.065487*       0.1750\n",
      "FIRE:  266 19:34:25     -431.065540*       0.1750\n",
      "FIRE:  267 19:34:25     -431.065701*       0.1750\n",
      "FIRE:  268 19:34:25     -431.065861*       0.1750\n",
      "FIRE:  269 19:34:26     -431.066074*       0.1749\n",
      "FIRE:  270 19:34:26     -431.066368*       0.1748\n",
      "FIRE:  271 19:34:26     -431.066662*       0.1747\n",
      "FIRE:  272 19:34:26     -431.067062*       0.1746\n",
      "FIRE:  273 19:34:27     -431.067570*       0.1745\n",
      "FIRE:  274 19:34:27     -431.068184*       0.1743\n",
      "FIRE:  275 19:34:27     -431.068958*       0.1741\n",
      "FIRE:  276 19:34:27     -431.069920*       0.1739\n",
      "FIRE:  277 19:34:28     -431.071121*       0.1736\n",
      "FIRE:  278 19:34:28     -431.072590*       0.1731\n",
      "FIRE:  279 19:34:29     -431.074406*       0.1727\n",
      "FIRE:  280 19:34:29     -431.076622*       0.1721\n",
      "FIRE:  281 19:34:29     -431.079319*       0.1712\n",
      "FIRE:  282 19:34:30     -431.082577*       0.1703\n",
      "FIRE:  283 19:34:30     -431.086582*       0.1690\n",
      "FIRE:  284 19:34:31     -431.091309*       0.2430\n",
      "FIRE:  285 19:34:31     -431.096409*       0.9863\n",
      "FIRE:  286 19:34:31     -431.095955*       3.5039\n",
      "FIRE:  287 19:34:32     -431.103378*       0.4813\n",
      "FIRE:  288 19:34:32     -431.103485*       0.3409\n",
      "FIRE:  289 19:34:33     -431.103645*       0.1630\n",
      "FIRE:  290 19:34:33     -431.103752*       0.1630\n",
      "FIRE:  291 19:34:33     -431.103859*       0.3180\n",
      "FIRE:  292 19:34:34     -431.104046*       0.3486\n",
      "FIRE:  293 19:34:34     -431.104340*       0.2394\n",
      "FIRE:  294 19:34:34     -431.104607*       0.1626\n",
      "FIRE:  295 19:34:34     -431.104954*       0.1857\n",
      "FIRE:  296 19:34:35     -431.105354*       0.2832\n",
      "FIRE:  297 19:34:35     -431.105915*       0.1622\n",
      "FIRE:  298 19:34:35     -431.106556*       0.1619\n",
      "FIRE:  299 19:34:36     -431.107384*       0.2497\n",
      "FIRE:  300 19:34:36     -431.108398*       0.1611\n",
      "FIRE:  301 19:34:36     -431.109600*       0.2436\n",
      "FIRE:  302 19:34:36     -431.111149*       0.1599\n",
      "FIRE:  303 19:34:37     -431.112965*       0.2383\n",
      "FIRE:  304 19:34:37     -431.115181*       0.2756\n",
      "FIRE:  305 19:34:37     -431.117878*       0.2263\n",
      "FIRE:  306 19:34:37     -431.121082*       0.3096\n",
      "FIRE:  307 19:34:38     -431.124580*       0.7986\n",
      "FIRE:  308 19:34:38     -431.126102*       2.3552\n",
      "FIRE:  309 19:34:38     -431.129414*       0.1511\n",
      "FIRE:  310 19:34:39     -431.129440*       0.1510\n",
      "FIRE:  311 19:34:39     -431.129494*       0.1510\n",
      "FIRE:  312 19:34:39     -431.129601*       0.1509\n",
      "FIRE:  313 19:34:39     -431.129707*       0.1508\n",
      "FIRE:  314 19:34:39     -431.129868*       0.1508\n",
      "FIRE:  315 19:34:40     -431.130054*       0.1507\n",
      "FIRE:  316 19:34:40     -431.130241*       0.1506\n",
      "FIRE:  317 19:34:40     -431.130508*       0.1504\n",
      "FIRE:  318 19:34:40     -431.130802*       0.1502\n",
      "FIRE:  319 19:34:41     -431.131229*       0.1500\n",
      "FIRE:  320 19:34:41     -431.131737*       0.1497\n",
      "FIRE:  321 19:34:41     -431.132378*       0.1493\n",
      "FIRE:  322 19:34:42     -431.133179*       0.1489\n",
      "FIRE:  323 19:34:42     -431.134113*       0.1483\n",
      "FIRE:  324 19:34:42     -431.135288*       0.1476\n",
      "FIRE:  325 19:34:43     -431.136757*       0.1466\n",
      "FIRE:  326 19:34:43     -431.138493*       0.1455\n",
      "FIRE:  327 19:34:43     -431.140629*       0.1441\n",
      "FIRE:  328 19:34:43     -431.143166*       0.1423\n",
      "FIRE:  329 19:34:44     -431.146236*       0.1401\n",
      "FIRE:  330 19:34:44     -431.149734*       0.4731\n",
      "FIRE:  331 19:34:44     -431.151684*       2.0240\n",
      "FIRE:  332 19:34:45     -431.154114*       0.2938\n",
      "FIRE:  333 19:34:45     -431.154167*       0.2103\n",
      "FIRE:  334 19:34:45     -431.154221*       0.1338\n",
      "FIRE:  335 19:34:46     -431.154301*       0.1337\n",
      "FIRE:  336 19:34:46     -431.154381*       0.1889\n",
      "FIRE:  337 19:34:46     -431.154488*       0.2107\n",
      "FIRE:  338 19:34:47     -431.154675*       0.1462\n",
      "FIRE:  339 19:34:47     -431.154835*       0.1333\n",
      "FIRE:  340 19:34:47     -431.155048*       0.1331\n",
      "FIRE:  341 19:34:48     -431.155315*       0.1677\n",
      "FIRE:  342 19:34:48     -431.155663*       0.1326\n",
      "FIRE:  343 19:34:48     -431.156063*       0.1322\n",
      "FIRE:  344 19:34:48     -431.156597*       0.1493\n",
      "FIRE:  345 19:34:49     -431.157211*       0.1312\n",
      "FIRE:  346 19:34:49     -431.157986*       0.1480\n",
      "FIRE:  347 19:34:49     -431.158947*       0.1296\n",
      "FIRE:  348 19:34:49     -431.160122*       0.1328\n",
      "FIRE:  349 19:34:50     -431.161510*       0.1826\n",
      "FIRE:  350 19:34:50     -431.163193*       0.1951\n",
      "FIRE:  351 19:34:50     -431.165169*       0.3116\n",
      "FIRE:  352 19:34:50     -431.167252*       0.7590\n",
      "FIRE:  353 19:34:51     -431.167812*       2.0195\n",
      "FIRE:  354 19:34:51     -431.170322*       0.1187\n",
      "FIRE:  355 19:34:51     -431.170322*       0.1187\n",
      "FIRE:  356 19:34:51     -431.170376*       0.1187\n",
      "FIRE:  357 19:34:52     -431.170429*       0.1186\n",
      "FIRE:  358 19:34:52     -431.170483*       0.1185\n",
      "FIRE:  359 19:34:52     -431.170589*       0.1184\n",
      "FIRE:  360 19:34:52     -431.170670*       0.1183\n",
      "FIRE:  361 19:34:52     -431.170803*       0.1182\n",
      "FIRE:  362 19:34:53     -431.170963*       0.1181\n",
      "FIRE:  363 19:34:53     -431.171150*       0.1179\n",
      "FIRE:  364 19:34:53     -431.171417*       0.1176\n",
      "FIRE:  365 19:34:54     -431.171711*       0.1174\n",
      "FIRE:  366 19:34:54     -431.172085*       0.1170\n",
      "FIRE:  367 19:34:54     -431.172539*       0.1165\n",
      "FIRE:  368 19:34:54     -431.173126*       0.1160\n",
      "FIRE:  369 19:34:54     -431.173847*       0.1153\n",
      "FIRE:  370 19:34:55     -431.174702*       0.1144\n",
      "FIRE:  371 19:34:55     -431.175743*       0.1134\n",
      "FIRE:  372 19:34:55     -431.176998*       0.1122\n",
      "FIRE:  373 19:34:55     -431.178520*       0.1107\n",
      "FIRE:  374 19:34:56     -431.180389*       0.1089\n",
      "FIRE:  375 19:34:56     -431.182552*       0.1067\n",
      "FIRE:  376 19:34:56     -431.185009*       0.4585\n",
      "FIRE:  377 19:34:56     -431.184689*       2.4095\n",
      "FIRE:  378 19:34:57     -431.187653*       0.8831\n",
      "FIRE:  379 19:34:57     -431.187920*       0.5848\n",
      "FIRE:  380 19:34:57     -431.188133*       0.1010\n",
      "FIRE:  381 19:34:57     -431.188107*       0.4112\n",
      "FIRE:  382 19:34:58     -431.188133*       0.3762\n",
      "FIRE:  383 19:34:58     -431.188160*       0.3094\n",
      "FIRE:  384 19:34:58     -431.188187*       0.2160\n",
      "FIRE:  385 19:34:58     -431.188240*       0.1064\n",
      "FIRE:  386 19:34:58     -431.188267*       0.1008\n",
      "FIRE:  387 19:34:59     -431.188293*       0.1089\n",
      "FIRE:  388 19:34:59     -431.188293*       0.1835\n",
      "FIRE:  389 19:34:59     -431.188347*       0.2268\n",
      "FIRE:  390 19:34:59     -431.188374*       0.2282\n",
      "FIRE:  391 19:35:00     -431.188454*       0.1782\n",
      "FIRE:  392 19:35:00     -431.188534*       0.1005\n",
      "FIRE:  393 19:35:00     -431.188641*       0.1004\n",
      "FIRE:  394 19:35:00     -431.188747*       0.1553\n",
      "FIRE:  395 19:35:01     -431.188881*       0.1796\n",
      "FIRE:  396 19:35:01     -431.189041*       0.1000\n"
     ]
    }
   ],
   "source": [
    "result = relaxer.relax(supercell)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df_magmom = pd.DataFrame({\"Unrelaxed\": chgnet.predict_structure(supercell)[\"m\"]})\n",
    "df_magmom[\"CHGNet relaxed\"] = result[\"final_structure\"].site_properties[\"magmom\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "alignmentgroup": "True",
         "bingroup": "x",
         "hovertemplate": "variable=Unrelaxed<br>value=%{x}<br>count=%{y}<extra></extra>",
         "legendgroup": "Unrelaxed",
         "marker": {
          "color": "#636efa",
          "opacity": 0.7,
          "pattern": {
           "shape": ""
          }
         },
         "name": "Unrelaxed",
         "nbinsx": 200,
         "offsetgroup": "Unrelaxed",
         "orientation": "v",
         "showlegend": true,
         "type": "histogram",
         "x": [
          0.005846306681632996,
          0.00613798201084137,
          0.005838409066200256,
          0.006123289465904236,
          0.005873620510101318,
          0.005982205271720886,
          0.0057303160429000854,
          0.006227895617485046,
          3.79987907409668,
          3.779931783676147,
          3.7868943214416504,
          3.7894020080566406,
          3.7995412349700928,
          3.779109954833984,
          3.7934515476226807,
          3.781636953353882,
          3.78696608543396,
          3.810993909835815,
          3.7647416591644287,
          3.7873964309692383,
          3.7893259525299072,
          3.8197214603424072,
          3.761281728744507,
          3.777733087539673,
          0.05601954460144043,
          0.07573537528514862,
          0.2507769465446472,
          0.0897427499294281,
          0.08101144433021545,
          0.053686752915382385,
          0.37213391065597534,
          0.06268421560525894,
          0.09365997463464736,
          0.04424618184566498,
          0.06020834296941757,
          0.05907696112990379,
          0.09364965558052064,
          0.044228605926036835,
          0.060205888003110886,
          0.05905310437083244,
          0.04214832931756973,
          0.06075103580951691,
          0.09063081443309784,
          0.0669855922460556,
          0.042021870613098145,
          0.06116792559623718,
          0.08966894447803497,
          0.06688324362039566,
          0.21097740530967712,
          0.05070599913597107,
          0.10366262495517732,
          0.09718137979507446,
          0.21097500622272491,
          0.05070560425519943,
          0.10366148501634598,
          0.09718002378940582
         ],
         "xaxis": "x",
         "yaxis": "y"
        },
        {
         "alignmentgroup": "True",
         "bingroup": "x",
         "hovertemplate": "variable=CHGNet relaxed<br>value=%{x}<br>count=%{y}<extra></extra>",
         "legendgroup": "CHGNet relaxed",
         "marker": {
          "color": "#EF553B",
          "opacity": 0.7,
          "pattern": {
           "shape": ""
          }
         },
         "name": "CHGNet relaxed",
         "nbinsx": 200,
         "offsetgroup": "CHGNet relaxed",
         "orientation": "v",
         "showlegend": true,
         "type": "histogram",
         "x": [
          0.0041740089654922485,
          0.005659803748130798,
          0.005208298563957214,
          0.005764618515968323,
          0.005141600966453552,
          0.0042886883020401,
          0.00534568727016449,
          0.0044854432344436646,
          3.8536534309387207,
          3.3298707008361816,
          3.2404894828796387,
          3.8762378692626953,
          3.261282444000244,
          3.867035627365112,
          3.9094491004943848,
          3.209686756134033,
          3.845051288604736,
          3.2448220252990723,
          3.2638800144195557,
          3.873450756072998,
          3.836575984954834,
          3.8892550468444824,
          3.2769529819488525,
          3.223111152648926,
          0.04621821641921997,
          0.0621287003159523,
          0.13308601081371307,
          0.06623542308807373,
          0.05322102829813957,
          0.04919075965881348,
          0.18662625551223755,
          0.05207786709070206,
          0.08124760538339615,
          0.06774012744426727,
          0.07822421193122864,
          0.07178786396980286,
          0.07889244705438614,
          0.06591508537530899,
          0.07653819024562836,
          0.0691024586558342,
          0.06811457872390747,
          0.07208065688610077,
          0.07142336666584015,
          0.0802316814661026,
          0.07145033776760101,
          0.07261765748262405,
          0.0752686858177185,
          0.08195497840642929,
          0.11541777849197388,
          0.04745578393340111,
          0.07534382492303848,
          0.06585996598005295,
          0.12135200202465056,
          0.05037090182304382,
          0.07928834110498428,
          0.06925031542778015
         ],
         "xaxis": "x",
         "yaxis": "y"
        }
       ],
       "layout": {
        "barmode": "overlay",
        "legend": {
         "title": {
          "text": ""
         },
         "tracegroupgap": 0,
         "x": 1,
         "xanchor": "right",
         "y": 1,
         "yanchor": "top"
        },
        "margin": {
         "t": 60
        },
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "#C8D4E3",
             "linecolor": "#C8D4E3",
             "minorgridcolor": "#C8D4E3",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "#C8D4E3",
             "linecolor": "#C8D4E3",
             "minorgridcolor": "#C8D4E3",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "white",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "#C8D4E3"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "white",
          "polar": {
           "angularaxis": {
            "gridcolor": "#EBF0F8",
            "linecolor": "#EBF0F8",
            "ticks": ""
           },
           "bgcolor": "white",
           "radialaxis": {
            "gridcolor": "#EBF0F8",
            "linecolor": "#EBF0F8",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           },
           "yaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           },
           "zaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           },
           "bgcolor": "white",
           "caxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "#EBF0F8",
           "linecolor": "#EBF0F8",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "#EBF0F8",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "#EBF0F8",
           "linecolor": "#EBF0F8",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "#EBF0F8",
           "zerolinewidth": 2
          }
         }
        },
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ],
         "range": [
          3,
          4
         ],
         "title": {
          "text": "Magnetic moment"
         }
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0,
          1
         ],
         "title": {
          "text": "count"
         }
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = df_magmom.hist(\n",
    "    nbins=200,\n",
    "    sharex=True,\n",
    "    sharey=True,\n",
    "    backend=\"plotly\",\n",
    "    barmode=\"overlay\",\n",
    "    layout={\"title\": \"Magmom distribution\"},\n",
    "    opacity=0.7,\n",
    "    range_x=[3, 4],\n",
    "    template=\"plotly_white\",\n",
    ")\n",
    "fig.layout.legend.update(title=\"\", x=1, y=1, xanchor=\"right\", yanchor=\"top\")\n",
    "fig.layout.xaxis.title = \"Magnetic moment\"\n",
    "fig.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py311",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
